package api

import (
    "fmt"
    "github.com/gogf/gf/net/ghttp"
    "webserver/app/service"
    "webserver/library/response"
    "webserver/library/utils"
)

var Mail = mailApi{}

type mailApi struct{}

func (a *mailApi) MailNotice(r *ghttp.Request) {
    params := r.GetRequestMapStrStr()
    fmt.Println(params)
    //params := make(map[string]string)
    //params["mailTo"] = "315959139@qq.com"
    //params["mailBody"] = "数据通知"
    if len(params["mailBody"]) == 0 {
        response.JsonExit(r, 1, "参数错误[mailBody]")
    }
    to := "315959139@qq.com"
    if len(params["mailTo"]) > 0 {
        to = params["mailTo"] + ";" + to
    }
    subject := "数据通知"
    body := params["mailBody"]
    err := utils.SendToMail(to, subject, body, "html")
    if err == nil {
        response.JsonExit(r, 0, "success")
    }
    response.JsonExit(r, 1, "Error:"+err.Error())
}

func (a *mailApi) FuturesPriceNotice(r *ghttp.Request) {
    err := service.HiFuturesQuoteService.CheckAllFuturesQuote(r)
    if err == nil {
        response.JsonExit(r, 0, "success")
    }
    response.JsonExit(r, 1, "Error:"+err.Error())
}
